package com.xiangmo.travel.mapper;
import java.util.List;

import com.xiangmo.travel.Dto.TeamTapCountDto;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xiangmo.travel.Entity.Team;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
* @author a1304
* @description 针对表【team】的数据库操作Mapper
* @createDate 2023-03-23 09:21:06
* @Entity generator.Entity.Team
*/
@Repository
public interface TeamMapper extends BaseMapper<Team> {
    //校验是否已经存在 不可再进行组队
    Team selectAllByAttractionsIdAndUserId(@Param("attractionsId") Long attractionsId, @Param("userId") Long userId);

    List<Team> selectAllByAttractionsIdAndUserIdAndStatus(@Param("attractionsId") Long attractionsId, @Param("userId") Long userId, @Param("status") Integer status);
    //改变队伍状态 结束状态
    int updateStatusById(@Param("status") Integer status, @Param("id") Long id);
    //通过组队id查询队长id
    Team selectUserIdById(@Param("id") Long id);
    //排行榜 通过组队次数
    @Select("SELECT team_users.user_id, COUNT(*) AS total FROM (SELECT user_id FROM team_user UNION ALL SELECT user_id FROM team) AS team_users GROUP BY user_id ORDER BY total DESC LIMIT 10")
    List<TeamTapCountDto> selectTop10UserByTeamCount();
    //队长id查询
    List<Team> selectByUserId(@Param("userId") Long userId);

}
